package com.example.mushroom.controller;

import com.example.mushroom.entity.Environment;
import com.example.mushroom.service.EnvironmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/environments")
public class EnvironmentController {

    @Autowired
    private EnvironmentService environmentService;

    @PostMapping
    public int insertEnvironment(@RequestBody Environment environment) {
        return environmentService.insertEnvironment(environment);
    }

    @GetMapping("/{id}")
    public Environment selectEnvironmentById(@PathVariable Integer id) {
        return environmentService.selectEnvironmentById(id);
    }

    @GetMapping
    public List<Environment> selectAllEnvironments() {
        return environmentService.selectAllEnvironments();
    }

    @PutMapping
    public int updateEnvironment(@RequestBody Environment environment) {
        return environmentService.updateEnvironment(environment);
    }

    @DeleteMapping("/{id}")
    public int deleteEnvironmentById(@PathVariable Integer id) {
        return environmentService.deleteEnvironmentById(id);
    }

    @GetMapping("/page")
    public List<Environment> selectEnvironmentsByPage(@RequestParam int offset, @RequestParam int limit) {
        return environmentService.selectEnvironmentsByPage(offset, limit);
    }
}